//所有布局+细节微调+点击效果

<template>
  <!-- <div style="position: absolute; top: calc(50vh - 100px); left: calc(50vw - 100px); width: 200px; height: 200px;">
    <video src="../assets/main_video.mp4" muted autoplay loop></video>
  </div> -->
  <!-- <div class="main-frame-container" :style="{ backgroundImage: `url(${website_bg_url})` }"> -->
  <div class="main-frame-container" :style="{ backgroundImage: '../assets/main/背景all.png' }">

    <div class="main-frame-nav-title">
      智慧AI创新平台
    </div>
    <div style="display: flex; justify-content: end;">
      <UserInfo :userDetail="userDetail"></UserInfo>
    </div>
    <!-- <img class="main-frame-nav" src="../assets/main/navigation.png" alt="顶部导航" /> -->
    <!-- <img class="main-frame-border" src="../assets/main/frameBg.png" alt="边框" /> -->
    <div class="main-frame-content">
      <el-row :gutter="80" class="box-container">
        <el-col :span="6" v-for="(item, index) in menuTop" :key="index">
          <div class="box-item" @click="handleClick(item, $event)" :class="{ 'active': item.isActive }"
               @mouseover="(e) => e.currentTarget['src'] = item.isActive = true"
               @mouseout="(e) => e.currentTarget['src'] = item.isActive = false">
            <img class="box-icon" :src="item.img" alt="图标" />
            <span class="box-title">{{ item.title }}</span>
          </div>
        </el-col>
      </el-row>

      <div class="module-container">
        <el-row :gutter="80" class="">
          <el-col :span="6" v-for="(item, index) in menuItems" :key="index" class="module-col">
            <div class="module-item" @click="handleClick(item, $event)">
              <!-- 图标部分 -->
              <div class="module-icon">
                <!-- <i :class="item.img"></i> -->
                <img :src="item.img" alt="图标" />
              </div>
              <!-- 文字部分 -->
              <div class="module-text-con">
                <!-- 左侧图标 -->
                <div class="module-text-icon">
                  <el-icon>
                    <CaretLeft />
                  </el-icon>
                </div>
                <div class="module-text">{{ item.title }}{{ item.titlePro ? ' | ' + item.titlePro : '' }}</div>
                <!-- 右侧图标 -->
                <div class="module-text-icon">
                  <el-icon>
                    <CaretRight />
                  </el-icon>
                </div>
              </div>
            </div>
          </el-col>
        </el-row>
      </div>
    </div>
    <div class="copyright">
      © 2025 智慧AI创新平台. All rights reserved.
    </div>
  </div>
</template>

<script setup lang="ts">
import { ref, onMounted, computed } from 'vue'
import icon1 from '../assets/main/eb452d4b33d9b48fd1cc8a107ae7a70fa0abd0a91b5e22-xiq08b.png'
import icon2 from '../assets/main/84161636efb2a50f23e890e44a7f2266126e5c8010cac6-pXcuMI.png'
import icon3 from '../assets/main/eb5fdc1be6f08e2209ddb4be3537113b310e77c11b4fe4-DA5M8Y.png'
import icon4 from '../assets/main/44167d27e86d3783ff369f89f57a444aacb2de4f14da63-0xL1Ch.png'

// 导入菜单背景图片
import deepseekBg from '../assets/main/deepseek.png'
import aiAppBg from '../assets/main/ppt.png'
import aiVisionBg from '../assets/main/aiVisionBg.png'
import digitalHumanBg from '../assets/main/digitalHumanBg.png'
import batchVideoBg from '../assets/main/batchVideoBg.png'
import batchImageBg from '../assets/main/batchImageBg.png'
import collageBg from '../assets/main/collageBg.png'

// import deepseekBgCK from '../assets/main/deepseekBgCK.png'
// import aiAppBgCK from '../assets/main/aiAppBgCK.png'
// import aiVisionBgCK from '../assets/main/aiVisionBgCK.png'
// import digitalHumanBgCK from '../assets/main/digitalHumanBgCK.png'
// import batchVideoBgCK from '../assets/main/batchVideoBgCK.png'
// import batchImageBgCK from '../assets/main/batchImageBgCK.png'
// import collageBgCK from '../assets/main/collageBgCK.png'
import { CaretRight } from '@element-plus/icons-vue'

import UserInfo from './userinfo/UserInfo.vue';
import axiosUtil from '../axios-util/axios-util'
import LocalStorageUtil from '../utils/LocalStorageUtil'
import router from '../routers/router'
import { ElMessage } from 'element-plus'

const userDetail = ref({});
const website_bg_url = ref('');

const menuTop = ref([
  {
    img: icon1,
    title: "多功能剪辑",
    isActive: false,
    url: import.meta.env.VITE_APP_SERVER+'storeplugin/clip/index?jump_url=../make_video&menu_url=make_video_1&type=1',
  },
  {
    img: icon2,
    title: "热点洞察",
    isActive: false,
    url: '/hotspot'
  },
  {
    img: icon3,
    title: "流量洞察",
    isActive: false,
    url: '/internetTraffic'
  },
  {
    img: icon4,
    // title: "矩阵营销",
    title: "扫码发布",
    isActive: false,
    url: '/matrix'
  }
])

const menuItems = ref([
  {
    img: batchVideoBg,
    title: "批量成片",
    isActive: false,
    isLeft: false,
    url: '/batchVideoBg'
  },
  {
    img: digitalHumanBg,
    title: "数字人",
    isActive: false,
    isLeft: false,
    url: '/digitalHumanBg'
  },
  {
    img: aiVisionBg,
    title: '文生图',
    titlePro: '文生图Pro',
    url: '/aiVisionBg',
    urlPro: '/aiVisionBgPro',
    isLeft: true,
    isActive: false
  },
  {
    img: deepseekBg,
    title: 'DeepSeek火山版',
    // url: './deepseekBg',
    /*url: import.meta.env.VITE_APP_SERVER+'storeplugin/index?jump_url=ai_ds&menu_url=ai_ds&storeid='+
      LocalStorageUtil.get("id")+'&token='+LocalStorageUtil.get("token"),*/
    url: import.meta.env.VITE_APP_SERVER+'storeplugin/ai_ds&menu_url=ai_ds&storeid='+
        LocalStorageUtil.get("id")+'&token='+LocalStorageUtil.get("token"),
    isLeft: false,
    isActive: false
  },
  {
    img: batchImageBg,
    title: '图生视频',
    titlePro: '图生视频Pro',
    isActive: false,
    isLeft: true,
    url: '/image2Video',
    urlPro: '/Image2VideoPro',
  },
  {
    img: aiAppBg,
    title: '文生视频',
    titlePro: '文生视频Pro',
    isActive: false,
    isLeft: true,
    url: '/text2Video',
    urlPro: '/text2VideoPro',
  },
  {
    img: collageBg,
    title: '文案提取',
    isActive: false,
    isLeft: false,
    url: '/getTxtFromMaterial',
  },
  {
    img: collageBg,
    title: '多功能实验室',
    isActive: false,
    isLeft: false,
    url: import.meta.env.VITE_APP_SERVER+'storeplugin/index?jump_url=tuiguang_user&menu_url=tuiguang_user',
  },
  /* {
     img: batchImageBg,
     title: '图生视频Pro',
     isActive: false,
     isLeft: false,
     url: '/Image2VideoPro',
   },
   {
     img: aiAppBg,
     title: '文生视频Pro',
     isActive: false,
     isLeft: false,
     url: '/text2VideoPro',
   },*/
  // {
  //   img: collageBg,
  //   title: '数据统计',
  //   isActive: false,
  //   url: '/dataStatistics',
  // },
])

const handleClick = (item, event) => {
  // 判断当前的div，以div宽的中间点分割，点击的是左边还是右边，左边是1，右边是2
  const div = event.currentTarget; // 获取当前被点击的元素
  const divRect = div.getBoundingClientRect(); // 获取元素相对于视口的位置和尺寸
  const divWidth = divRect.width;
  const divX = divRect.left;
  const divCenterX = divX + divWidth / 2;
  const clickX = event.clientX;

  if (item.isLeft) {
    if(!(clickX < divCenterX)) {
      item.url = item.urlPro;
      item.title = item.titlePro;
    }
  }
  // 判断是否可用
  let userDetailInfo:any = LocalStorageUtil.get('userDetailInfo');
  if(item.title == '图生视频' && userDetailInfo.i2vstatus == '2') {
    ElMessage.error('您没有开通图生视频模块权限');
    return;
  }
  if(item.title == '文生视频' && userDetailInfo.t2vstatus == '2') {
    ElMessage.error('您没有开通文生视频模块权限');
    return;
  }
  if(item.title == '数字人' && userDetailInfo.prostatus == '2') {
    ElMessage.error('您没有开通数字人模块权限');
    return;
  }
  if(item.title == '多功能实验室') {
    // ElMessage.error('该模型功能正在开发中，敬请期待');
    // return;
    item.url = '/laboratory';
  }


  if (item.url.indexOf('http') !== -1) {
    window.open(item.url, '_blank')
  } else {
    router.push(item.url)
    // window.location.href = item.url
  }
}

//读取配置，获取网站背景图
const initWebsiteConfig = async () => {
  const response = await axiosUtil.post('api/pc/site/get_agent_config', {})
  if (response.data.code === 0 && response.data.data) {
    // 缓存到浏览器缓存
    LocalStorageUtil.set('WebsiteConfig', response.data.data)
  }
}

const getInfo = async() => {
  const response = await axiosUtil.post('api/store/info', {host:{}})
  if (response.data.code === 1 && response.data.data) {
    userDetail.value = response.data.data;
    // 缓存到浏览器缓存
    LocalStorageUtil.set('userDetailInfo', response.data.data, 7 * 24 * 60 * 60 * 1000)
  }
}

//读取配置，获取网站背景图
const initWebsiteBgUrl = async () => {
  const response = await axiosUtil.post('api/pc/site/get_agent_config', {})
  if (response.data.code === 0 && response.data.data) {
    website_bg_url.value = import.meta.env.VITE_APP_SERVER + response.data.data.website_bg || ''
  }
}

onMounted(() => {
  document.body.classList.remove('login-page');
  initWebsiteBgUrl();
  // 读取用户的config配置
  initWebsiteConfig();
  // 调取info接口，获取用户的详细信息
  getInfo();
})
</script>

<style scoped>
.main-frame-container {
  position: relative;
  width: 100%;
  min-height: 100vh;
  overflow-x: hidden;
  background: url(../assets/main/背景all.png) no-repeat center center;
  background-size: 100% 100%;
}

.main-frame-nav {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: auto;
  z-index: 2;
  pointer-events: none;
}

.main-frame-nav-title {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 94px;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  padding-top: 10px;
  z-index: 3;
  color: #fff;
  font-size: 3.3vh;
  font-weight: bold;
  text-shadow: 0 2px 8px #003366, 0 0 16px #00aaff;
  letter-spacing: clamp(2px, 2vw, 6px);
  pointer-events: none;
  user-select: none;
}

.main-frame-border {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 1;
  pointer-events: none;
}

.main-frame-content {
  position: relative;
  z-index: 3;
  width: 100%;
  height: 100%;
  padding: 0 1rem;
}

.box-container {
  padding: 100px 50px 20px 50px;
}

.box-item {
  background: url(../assets/main/border_bg01.png) no-repeat center center;
  background-size: 100% 100%;
  height: clamp(80px, 10vh, 100px);
  width: 100%;
  max-width: 300px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 15px;
  cursor: pointer;
  transition: all 0.4s;
}

.box-item:hover {
  transform: scale(1.1);
}

.box-item.active {
  background: url(../assets/main/checkedBg.png) no-repeat center center;
  background-size: 100% 100%;
}

.box-icon {
  width: clamp(40px, 5vw, 60px);
  height: clamp(40px, 5vw, 60px);
  margin-right: 15px;
}

.box-title {
  color: #fff;
  font-size: clamp(1rem, 2vw, 1.3rem);
  font-weight: bold;
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.5);
  white-space: nowrap;
}

.module-container {
  padding: 30px 50px;
  background: transparent;
  max-height: 60vh; /* 设置最大高度 */
  overflow-y: auto; /* 启用垂直滚动 */
  overflow-x: hidden; /* 隐藏水平滚动 */
  /* 隐藏滚动条但保持滚动功能 */
  scrollbar-width: none; /* Firefox */
  -ms-overflow-style: none; /* IE and Edge */
}

/* 隐藏Webkit浏览器的滚动条 */
.module-container::-webkit-scrollbar {
  display: none;
}

/* 模块列样式 */
.module-col {
  margin-bottom: 20px;
}

/* 单个模块样式 */
.module-item {
  display: flex;
  padding: 10px 0;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 22vh;
  background: rgba(8, 71, 157, 0.15);
  border-radius: 4px;
  box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
  cursor: pointer;
  transition: all 0.3s;
  background-image: url(../assets/images/panel.png);
  background-size: 100% 100%;
}

.module-item:hover {
  transform: scale(1.02);
  /* 放大图片 */
  opacity: 1;
  /* 提高透明度 */
  box-shadow: 0 0 30px rgba(0, 255, 255, 1);
  /* 调整颜色和大小以达到期望的发光效果 */
}

.module-item::before {
  content: '';
  position: absolute;
  width: 10px;
  height: 10px;
  background-color: rgba(0, 255, 255, 0.8);
  border-radius: 50%;
  animation: none;
  z-index: 10;
}

/* .module-item:hover {
  transform: translateY(-5px);
  box-shadow: 0 4px 16px 0 rgba(0, 0, 0, 0.15);
} */

/* 图标样式 */
.module-icon {
  margin-bottom: -2vh;
}

.module-icon img {
  width: 7vw;
  height: 8vw;
}

.module-text-con {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 15px;
  background: transparent;
  border-radius: 8px;
  box-shadow: 0 3px 10px rgba(0, 0, 0, 0.08);
  cursor: pointer;
  transition: all 0.3s ease;
  /* border: 1px solid #ebeef5; */
}

.module-text-icon {
  font-size: 20px;
  color: #fff;
  margin: 0 10px;
  font-size: 18px;
  color: white;
}

/* 文字样式 */
.module-text {
  font-size: 18px;
  color: white;
  font-weight: 600;
}

/* 响应式调整（可选） */
@media (max-width: 768px) {
  .module-icon i {
    font-size: 28px;
  }

  .module-item {
    height: 100px;
  }
}

/* 响应式布局调整 */
@media screen and (max-width: 1200px) {
  .el-col {
    margin-bottom: 1rem;
  }
}

@media screen and (max-width: 768px) {
  .box-container {
    padding: 60px 10px 0;
  }

  .menu-box {
    height: 120px;
  }

  .box-item {
    height: 70px;
  }
}

@media screen and (max-width: 480px) {
  .main-frame-nav-title {
    height: 60px;
  }

  .box-container {
    padding: 40px 5px 0;
  }

  .menu-box {
    height: 100px;
  }

  .box-item {
    height: 60px;
  }
}

/* 光点沿边框旋转动画 */
@keyframes lightOrbit {
  0% {
    top: 0;
    left: 0;
  }

  25% {
    top: 0;
    right: 0;
  }

  50% {
    bottom: 0;
    right: 0;
  }

  75% {
    bottom: 0;
    left: 0;
  }

  100% {
    top: 0;
    left: 0;
  }
}

.copyright {
  margin-bottom: 15px;
  font-size: 14px;
  opacity: 0.8;
  color: white;
  text-align: center;
  bottom: 20px;
  width: 100%;
  position: absolute;
}
</style>

<style>
/* 隐藏全局背景图 */
body::before {
  display: none !important;
}

/* 优化Main页面背景图和滚动条 */
html,
body {
  height: 100%;
  width: 100%;
  margin: 0;
  padding: 0;
  overflow-x: hidden;
  overflow-y: auto;
}

/* 响应式调整 */
@media screen and (max-width: 768px) {
  .el-row {
    margin-left: 0 !important;
    margin-right: 0 !important;
  }

  .el-col {
    padding-left: 5px !important;
    padding-right: 5px !important;
  }
}
</style>
